package com.liujit.generator.engine.config;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.liujit.generator.GeneratorApplication;
import lombok.Data;

import java.util.Date;

/**
 * @Description 全局配置
 * @Author LiuJun
 * @Date 2020/8/13 11:42 上午
 */
@Data
public class ContextConfig {

    /**
     * 模版路径
     */
    private String templatePrefixPath = "template";

    /**
     * 模板输出的项目目录
     */
    private String projectPath;

    /**
     * 项目名称
     */
    private String projectName;

    /**
     * 来源
     */
    private String reqFrom;

    /**
     * 基础包名
     */
    private String basePackageName;

    /**
     * 包名
     */
    private String packageName;

    /**
     * 作者
     */
    private String author;

    /**
     * 表名称
     */
    private String tableName;

    /**
     * 业务名称
     */
    private String bizName;

    /**
     * 时间
     */
    private String dateTime;

    /**
     * Mapping名称
     */
    private String bizReqMappingName;

    /**
     * 小写
     */
    private String bizEnName;

    /**
     * 大写
     */
    private String bizEnBigName;

    /**
     * Controller开关
     */
    private Boolean controllerSwitch = false;

    /**
     * Service开关
     */
    private Boolean serviceSwitch = false;

    /**
     * Mapper开关
     */
    private Boolean mapperSwitch = false;

    /**
     * Model开关
     */
    private Boolean modelSwitch = false;

    /**
     * Query开关
     */
    private Boolean querySwitch = false;

    /**
     * Param开关
     */
    private Boolean paramsSwitch = false;

    /**
     * Result开关
     */
    private Boolean resultSwitch = false;

    public void init() {
        this.basePackageName = GeneratorApplication.class.getPackage().getName().replace(".generator", "");
        this.packageName = this.basePackageName + "." + this.projectName;
        if (StrUtil.isNotBlank(this.reqFrom)) {
            this.packageName = this.packageName + "." + this.reqFrom;
            this.reqFrom = "-" + this.reqFrom + "-";
        } else {
            this.reqFrom = "-";
        }
        this.dateTime = DateUtil.formatDateTime(new Date());
        this.bizReqMappingName = this.tableName.replace("_", "/");
        this.bizEnName = StrUtil.toCamelCase(this.tableName);
        this.bizEnBigName = StrUtil.upperFirst(this.bizEnName);
    }
}
